// https://leetcode.cn/problems/house-robber/
// Created by ade on 2022/8/25.
// 0-0 1-1 2-max(1,2) 3-max(1+3 , 2) 4-max(1,3 2,4 1,4) 5-max(1,3,5 2,4 | 1,4, 2,5)
//
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

class Solution {
public:
    int rob(vector<int> &nums) {
        int len = nums.size();
        if (len == 1) return nums[0];
        if (len == 2) return max(nums[0], nums[1]);
        vector<int> dp(len, 0);
        dp[0] = nums[0];
        dp[1] = max(nums[0], nums[1]);
        for (int i = 2; i < len; i++) {
            dp[i] = max(dp[i - 2] + nums[i], dp[i - 1]);
        }
        return dp[len - 1];
    }

    int rob(vector<int> &nums) {
        int len = nums.size();
        if (len == 1) return nums[0];
        if (len == 2) return max(nums[0], nums[1]);
        int pp = nums[0];
        int p = max(nums[0], nums[1]);
        for (int i = 2; i < len; i++) {
            int tmp = max(pp + nums[i], p);
            pp = p;
            p = tmp;

        }
        return p;
    }
};

int main() {
    Solution so;
    vector<int> s = {1, 2, 1, 3};
    auto res = so.rob(s);
    cout << res << endl;
    return 0;
}